<?php 
// src/Ipartek/BlogBundle/Listener/BlogRequestListener.php
namespace Ipartek\BlogBundle\Listener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\EngineInterface;

class BlogRequestListener
{

	
	public function onKernelRequest(GetResponseForControllerResultEvent  $event)
	{
	
	    $request = $event->getRequest();
	    $template = $request->get('_template');
	    
	    
	    $response = $this->templating->renderResponse('jeje.html.twig');
	    $event->setResponse($response);
	    
    	if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $request->headers->get('user-agent')))
    	{
    		// $request->setRequestFormat('mobile', 'text/html');
    		$request->attributes->add( array('formato'=>'_movil') );
    		$request->setRequestFormat('mobile', 'text/html');
    	}else {
    		// $request->setRequestFormat('html', 'text/html');
    		$request->attributes->add( array('formato'=>'') );
    	}

	}
	

    
    
}
